var express = require('express');
var router = express.Router();

var products = new Map(require('./upimgs.json'));
var articles = require("./article.json");
/* GET home page. */
router.get('/', function(req, res, next) {
  res.locals.user = req.session.user || "";
  let set = [];
  products.forEach(function(value,key,map){
    set.push(value);
    // console.log("value="+value.file.filename);
  });
  res.locals.products = set;
  res.locals.articles = articles;
  res.render('index');
});

router.get('/product', function(req, res){
  res.locals.user = req.session.user || "";
  let set = [];
  products.forEach(function(value,key,map){
    set.push(value);
  });
  res.locals.products = set;
  res.render('product');
});


router.get('/socket', function(req, res){
  res.locals.user = req.session.user || "";
  res.render('socket');
});

// router.get('/article', function(req, res){
//   res.locals.user = req.session.user || "";
//   res.render('article');
// });

var messages = require('./message.json');
router.get('/comment', function(req, res){
  res.locals.comments = messages;
  res.locals.user = req.session.user || "";
  // console.log(req.locals.comments);
  res.render('comment');
});

router.get('/register', function(req, res){
  res.render('register');
});

module.exports = router;
